<template>
  <div class="customer-reviews-section">
    <div class="review-container">
      <h2 class="review-title">CUSTOMER REVIEWS</h2>
      <div class="review-header">
        <button class="review-button" @click="showModal = true">review</button>
      </div>
    </div>
    <div class="no-reviews-message">
      <p>Be the first to write a <span class="review-link" @click="showModal = true">review</span></p>
    </div>

    <!-- Review Login Modal -->
    <div class="modal-overlay" v-if="showModal" @click.self="showModal = false">
      <div class="modal-content">
        <button class="close-button" @click="showModal = false">
          <span>×</span>
        </button>
        
        <div class="modal-body">
          <p class="modal-message">We appreciate your interest in leaving a review.</p>
          <p class="modal-message">Please note that only registered users can leave product reviews!</p>
          
          <button class="sign-in-button" @click="navigateToSignIn">Sign in</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineEmits, defineComponent, ref } from 'vue';
import { useRouter } from 'vue-router';

defineComponent({
  name: 'CustomerReview'
});

const emit = defineEmits(['write-review']);
const router = useRouter();
const showModal = ref(false);

// Function to handle review button click
const writeReview = () => {
  showModal.value = true;
  emit('write-review');
};

// Navigate to sign in page
const navigateToSignIn = () => {
  showModal.value = false;
  router.push('/login');
};
</script>

<style scoped lang="scss">
.customer-reviews-section {
  margin-top: 80px;
  margin-bottom: 30px;
  .review-container{
    display: flex;
    justify-content: space-between;
  }
}

.no-reviews-message {
  border-top: 1px solid #e5e5e5;
  padding-top: 10px;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.review-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.review-button {
  padding: 8px 20px;
  border: 1px solid #000;
  background-color: #fff;
  cursor: pointer;
  text-transform: lowercase;
  font-size: 14px;
  font-weight: 400;
  transition: background-color 0.3s, color 0.3s;

  &:hover {
    background-color: #000;
    color: #fff;
  }
}

.no-reviews-message {
  text-align: left;
  font-size: 14px;
  color: #333;

  p {
    margin: 0;
  }
}

.review-link {
  color: #3772ff;
  text-decoration: underline;
  cursor: pointer;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  padding: 30px;
  border-radius: 0;
  width: 100%;
  max-width: 500px;
  position: relative;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.close-button {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  text-align: center;
}

.modal-message {
  margin: 5px 0;
  font-size: 16px;
  line-height: 1.5;
  color: #333;
}

.sign-in-button {
  margin-top: 30px;
  padding: 10px 30px;
  background-color: white;
  border: 1px solid #000;
  color: #000;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s, color 0.3s;
  
  &:hover {
    background-color: #000;
    color: white;
  }
}

@media (max-width: 767px) {
  .review-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }

  .review-button {
    align-self: flex-end;
  }
  
  .modal-content {
    width: 90%;
    margin: 0 15px;
    padding: 20px;
  }
}
</style>